[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
strspn() Find First Substring
#include <string.h> Required for declarations only
size_t strspn(string1,string2);
const char *string1; Searched string
const char *string2; Character set
strspn() tests whether the first substring (i.e., the substring
beginning at the start of 'string1') in 'string1' consists entirely
of characters from character set 'string2'. (It does this by
searching 'string1' for the first occurrence of a character that is
not also in 'string2'.)
Returns: The index in 'string1' of the first character past
the substring that contains only characters from
'string2'. This is equal to the first character in
'string1' that is not among the characters in
'string2'. Looking at it another way, the index
value is equal to the length of the substring of
'string1' that is made up of characters from
'string2'.
-------------------------------- Example ---------------------------------
The following statements check whether 'string' begins with a vowel.
#include <string.h>
int rslt;
char *string = "imagination";
char *charset = "aeiou";
main()
{
if((rslt = strspn(string,charset)) > 0)
printf("string begins with a vowel\n");
}
See Also:
strcspn()
strstr()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson